#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long maximumOr(vector<int>& nums, int k) {
        using LL = long long;
        int n = nums.size();
        vector<LL> suffix(n, 0);
        for (int i = n - 2; i >= 0; i--)
        {
            suffix[i] = suffix[i + 1] | nums[i + 1];
        }
        LL prefix = 0;
        LL res = 0;
        for (int i = 0; i < n; i++)
        {
            LL s = (LL)nums[i] << k;
            res = max(res, (s | suffix[i] | prefix));
            prefix |= nums[i];
        }
        return res;
    }
};